package com.sweet.thread;



// 模拟网络延时 每个对象都有一把锁，sleep不会释放锁
public class TestSleep1 implements Runnable {
    private int ticketNum = 10;
    @Override
    public void run() {

        while (true) {
            if(ticketNum <= 0) {
                break;
            }
            // 模拟网络延时
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "拿到了第：" + (ticketNum--) + "张票。");
        }
    }

    public static void main(String[] args) {
        TestSleep1 t = new TestSleep1();
        new Thread(t, "小明").start();
        new Thread(t, "小华").start();
        new Thread(t, "小红").start();
    }
}
